﻿<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data.Sql;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using Newtonsoft.Json;

public class Handler : IHttpHandler {

    public void ProcessRequest(HttpContext context)
    {
        string strConn = UserClass.strconn;
        using (SqlConnection conn = new SqlConnection(strConn))
        {
            int count = 5;
            string table = "compare_"+count+"_products";
            List<int> cpList = new List<int>();
            string strCmd = @"SELECT production_product.product_id, production_product.product_name, production_image.image
                                            FROM production_product INNER JOIN
                                                       production_image ON production_product.product_id = production_image.product_id AND 
                                                       production_product.product_id = production_image.product_id
                                            WHERE (production_image.image_order = 1)";
            using (SqlCommand cmd = new SqlCommand(strCmd, conn))
            {
                cmd.Parameters.AddWithValue("@c_id", 3);
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    for (int i = 1; i <= count; i++)
                    {
                        cpList.Add(Convert.ToInt32(reader[i]));
                    }
                }
                context.Response.ContentType = "application/json";
                context.Response.Write(JsonConvert.SerializeObject(cpList));
                conn.Close();
            }
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}